package lifeOfAFish.test;
import lifeOfAFish.*;



import javax.media.opengl.GL;
import javax.media.opengl.GLAutoDrawable;

//import lifeOfAFish.modelLoader.ModelLoaderOBJ;
import lifeOfAFish.scenegraph.geom.sgGeomCuboid;
import lifeOfAFish.scenegraph.geom.sgGeomMesh;
import lifeOfAFish.scenegraph.sgGlobals;
import lifeOfAFish.scenegraph.sgLight;
import lifeOfAFish.scenegraph.sgLightFactory;
import lifeOfAFish.scenegraph.sgMaterial;
import lifeOfAFish.scenegraph.sgNode;
import lifeOfAFish.scenegraph.sgTransform;
import lifeOfAFish.test.JoglTemplate;



public class ScenePositions extends JoglTemplate {
	
	// the scene
	private sgNode root;
	private Scene scene;
	private sgLight light;
	
	
	// added by chris
	private sgGeomCuboid room;
	private sgGeomCuboid aquarium;
	private sgGeomCuboid bed;
	private sgGeomCuboid billard;
	private sgGeomMesh piano;
//	private sgGeomCuboid piano;
	private sgGeomCuboid table;
	
	private sgTransform rotPiano;

	
	//Particle System
//	private ParticleSystem ps;
	
	
	public static void main (String[] args){
		ScenePositions template = new ScenePositions();
		template.setVisible(true);
		
	}

	public void init(GLAutoDrawable drawable)
	{
		super.init(drawable);
		
		// get gl object
		GL gl = drawable.getGL();
		sgGlobals.gl = gl;
		
		// enable depth testing
//		gl.glEnable(GL.GL_DEPTH_TEST);
		gl.glDisable(GL.GL_DEPTH_TEST);
		gl.glDepthRange(0.0, 1000.0);
		
		// enable lighting
		gl.glEnable(GL.GL_LIGHTING);
		gl.glShadeModel(GL.GL_SMOOTH);

		// enable texture mapping
		gl.glEnable(GL.GL_TEXTURE_2D);
		
		// create the elements of the scene
		root = new sgNode();
		scene = new Scene();	
		scene.init();
		
		root.addChild(scene.getNode());
		
		float[] sourceRoom = {0.0f, 0.0f, 0.0f};
		
		// create room (depth, height, width = z (will point in "-z axis"), y, x, color)
		room = new sgGeomCuboid(sourceRoom, 7.0f, 3.2f, 10.0f);
		
		root.addChild(room);
		
		float[] sourceAquarium = {5.5f, 0.8f, -1.0f};
		sgMaterial mat2 = new sgMaterial();
		mat2.setAmbient(0.5f, 0.1f, 0.1f, 1.0f);
		mat2.setDiffuse(0.4f, 0.0f, 0.0f, 1.0f);
		mat2.setSpecular(1.0f, 1.0f, 1.0f, 1.0f);
		// create aquarium (depth, height, width = z (will point in "-z axis"), y, x, color)
		aquarium = new sgGeomCuboid(sourceAquarium, 2.0f, 1.2f, 3.5f);
		room.addChild(aquarium);
		
		float[] sourceBed = {6.75f, 0.0f, -4.75f};
		sgMaterial mat3 = new sgMaterial();
		mat3.setAmbient(0.5f, 0.1f, 0.1f, 1.0f);
		mat3.setDiffuse(0.4f, 0.0f, 0.0f, 1.0f);
		mat3.setSpecular(1.0f, 1.0f, 1.0f, 1.0f);
		// create bed (depth, height, width = z (will point in "-z axis"), y, x, color)
		bed = new sgGeomCuboid(sourceBed, 2.25f, 0.4f, 2.25f);
		room.addChild(bed);
		
		float[] sourceBillard = {1.5f, 0.0f, -4.68f};
		sgMaterial mat4 = new sgMaterial();
		mat4.setAmbient(0.5f, 0.5f, 0.5f, 1.0f);
		mat4.setDiffuse(0.4f, 0.2f, 0.3f, 1.0f);
		mat4.setSpecular(1.0f, 1.0f, 1.0f, 1.0f);
		// create billard (depth, height, width = z (will point in "-z axis"), y, x, color)
		billard = new sgGeomCuboid(sourceBillard, 1.57f, 0.82f, 2.84f);
		room.addChild(billard);
		
		float[] sourcePiano = {1.0f, 0.0f, -1.0f};
		sgMaterial mat5 = new sgMaterial();
		mat5.setAmbient(0.0f, 0.0f, 0.0f, 1.0f);
		mat5.setDiffuse(0.0f, 0.0f, 0.0f, 1.0f);
		mat5.setSpecular(1.0f, 1.0f, 1.0f, 1.0f);
		// create piano (depth, height, width = z (will point in "-z axis"), y, x, color)
		piano = new sgGeomMesh();
		piano.setOBJFileName("src/lifeOfAFish/models/Piano_optimized.obj");
		
//		piano.setTextureFileName("src/lifeOfAFish/models/BocaccT.bmp");
//		piano = new sgGeomCuboid(sourcePiano, 1.55f, 1.005f, 2.74f);
		room.addChild(piano);
		piano.load();
		
		float[] sourceTable = {5.375f, 0.0f, -0.875f};
		sgMaterial mat6 = new sgMaterial();
		mat6.setAmbient(0.5f, 0.1f, 0.1f, 1.0f);
		mat6.setDiffuse(0.4f, 0.0f, 0.0f, 1.0f);
		mat6.setSpecular(1.0f, 1.0f, 1.0f, 1.0f);
		// create piano (depth, height, width = z (will point in "-z axis"), y, x, color)
		table = new sgGeomCuboid(sourceTable, 2.25f, 0.8f, 3.75f);
		room.addChild(table);
		//root.addChild(new sgGeomCube(1.0f));
		
		light = sgLightFactory.newLight();
		float[] lpos = {1.0f, 1.0f, 1.0f, 1.0f}; 
		light.setPosition(lpos);
		root.addChild(light);

		
		
		//Particle System
//		ps = new ParticleSystem();
//		ps.init(gl);
		
	
		
		
		
		// print the scenegraph
		System.out.println(root);
		
		
		
	}
	
	/*
	 * overwritten version of display
	 */
	public void display(GLAutoDrawable drawable)
	{
		// get the gl object
		GL gl = drawable.getGL();
		// set the erasing color (black)
		gl.glClearColor(0f, 0f, 0f, 0f);
		// clear screen with the defined erasing color and depth buffer
		
		gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
		gl.glPushMatrix();
		applyMouseTranslation(gl);
		applyMouseRotation(gl);
		
		
		
		//------------------------------------------------------------------
//		gl.glEnable( GL.GL_FOG );
//	      gl.glHint( GL.GL_FOG_HINT, GL.GL_NICEST );
//	      //gl.glHint( GL.GL_FOG_HINT, GL.GL_FASTEST );
//
//	      //gl.glFogi( GL.GL_FOG_MODE, GL.GL_EXP );
//	      //gl.glFogi( GL.GL_FOG_MODE, GL.GL_EXP2 );
//	      //gl.glFogi( GL.GL_FOG_MODE, GL.GL_LINEAR );
//
//	      //Original:  gl.glFogf( GL.GL_FOG_DENSITY, 1.0f );
//	      gl.glFogf( GL.GL_FOG_DENSITY, 0.3f );
//	      gl.glFogf( GL.GL_FOG_START, 0 );
//	      gl.glFogf( GL.GL_FOG_END, 4);
//	      float fogColor[] = {0, 0, 0, 0.5f };
//	      gl.glFogfv( GL.GL_FOG_COLOR, fogColor, 0 );
//
//	      // Select how fog distance is calculated.
//	      //gl.glFogi( GL.GL_FOG_COORD_SRC, GL.GL_FOG_COORD );
//	      gl.glFogi( GL.GL_FOG_COORD_SRC, GL.GL_FRAGMENT_DEPTH );
		
		
		//------------------------------------------------------------------
		
		
		
		// render the scene
		root.traverse();
		
		
		
		//Draw Particle System
//		ps.draw(gl);

		// load an object using the mesh loader
		gl.glPopMatrix();
	}
	
}
